/////////////////////////////////////////////////////////////////////////////
// canvasUtils.js
// 拖动fabric image对象元素
function startPanViewport(canvas, event) {
    canvas.setCursor("move");
    canvas.isDragging = true;
    canvas.lastPosX = event.e.clientX;
    canvas.lastPosY = event.e.clientY;
}

function updatePanViewport(canvas, event) {
    if (canvas.isDragging) {
        canvas.setCursor("move");
        let vpt = canvas.viewportTransform;
        vpt[4] += event.e.clientX - canvas.lastPosX;
        vpt[5] += event.e.clientY - canvas.lastPosY;
        canvas.lastPosX = event.e.clientX;
        canvas.lastPosY = event.e.clientY;
    }
}

function stopPanViewport(canvas, event) {
    canvas.setCursor("crosshair");
    canvas.setViewportTransform(canvas.viewportTransform);
    canvas.isDragging = false;
}

export { startPanViewport, updatePanViewport, stopPanViewport };
